Skip to content

feat(codegen-kotlin): move the last Kotlin generators onto KotlinWriter and drop KotlinPoet - #664

Merged
dmealing merged 4 commits into
mainfrom
fm/mo-130-kt-writer-4
Nov 27, 2026
Merged

dmealing merged 4 commits into
mainfrom
fm/mo-130-kt-writer-4

Conversation

@dmealing

@dmealing dmealing commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • The entity, Spring config and enum generators, plus the MetaNetJson.kt support file, now lay out their output with KotlinWriter. KotlinPoetFileWriter is removed, and every file goes through GeneratedFileWriter's marker guard.
  • KotlinTypeMapper, KotlinCrossFieldRules and KotlinGenUtil return the writer's own KotlinTypeName / KotlinClassName (writer/KotlinTypeName.kt) instead of KotlinPoet types. The kotlinpoet-jvm dependency is removed from server/java/codegen-kotlin/pom.xml. A test-scoped kotlin-reflect is pinned to the module's Kotlin version.
  • Generated Kotlin changes layout only: no explicit public, no kotlin.* imports, four-space indent, one sorted import group. Owned copies ejected before 1.3.0 that use the removed KotlinPoet types need re-ejecting (documented in CHANGELOG.md).

Live evidence (head 8cbae52; the current head 3b7f82e only adds main's one-line tools/prerelease/candidates.md row, and the gate's local CI passed on it)

The gate's "no live product run" test note is declined on this evidence:

Run Result
Full Kotlin suite: mvn -pl codegen-kotlin -am -Dtest='com.metaobjects.generator.kotlin.**' test (goldens, codegen-kotlin compile gate CodegenCompileConformanceTest, layout ratchet, eject and ejected-at-base compat tests) 684 tests, 0 failures, 0 errors
integration-tests-kotlin: scripts/integration-test.sh kotlin (Testcontainers Postgres, persistence + api-contract corpora through Exposed) 462 tests, 0 failures, 0 errors, 7 skipped (the existing decimal api-contract skips)
exposed1x Postgres round trip: codegen-kotlin-exposed1x-check (same script) 5 tests, 0 failures
Pipeline local CI: scripts/ci-local.sh --affected --strict-toolchains (java reactor, all five conformance lanes, ts) passed

The review fix round moved kotlin-reflect from a runtime dependency of codegen-kotlin to a test-scope dependency of codegen-kotlin only, pinned to ${kotlin.version} (its own tests need it to match kotlin-stdlib); integration-tests-kotlin and the exposed1x check get it through jackson-module-kotlin, and both were re-run green on this head after that change.

Layout-only proof: the 32 regenerated goldens equal the previous ones once imports, public, package qualifiers, whitespace and trailing commas are normalised, with every comment's text unchanged; MetaNetJson.kt is byte-identical.

Validation

Risk Assessment

✅ Low: The only change since the approved head adds a 7-line ADR amendment. I checked each of its claims against the source: the Kotlin ratchet allowlist has an empty unconverted section, KotlinApiDocsRenderer is the only exempt entry, codegen-kotlin main code and pom.xml have no kotlinpoet reference, and docs/ports/kotlin.md exists and states the same facts.

Testing

Baseline scripts/ci-local.sh --affected --strict-toolchains already passed at this commit and was not re-run. This turn ran the focused offline codegen-kotlin Maven tests, which execute the moved generators in-process, compile emitted Kotlin, and pass. No live product scenario was driven: the Maven plugin metaobjects:generate run and a before/after output diff were not attempted within budget, so every scenario is untested with live=false. Verdict inconclusive, not go. No background processes left running and no source files changed.

  • Live validation: ⚠️ inconclusive - 0 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Kotlin entity generator emits through KotlinWriter with output unchanged in behavior ⏸️ untested no Only in-process unit tests ran. Live check needs metaobjects:generate through the Maven plugin on a fixture, diffed before and after the change; not attempted within budget.
Kotlin enum and Spring config generators emit through KotlinWriter ⏸️ untested no Same as above: in-process tests only, no live plugin or CLI run.
Generated Kotlin output compiles without kotlinpoet on the path ⏸️ untested no Compile gate ran in-process via the test suite, not against a live generate-then-kotlinc run of the product.
Adversarial: reintroducing KotlinPoet is blocked at build time ⏸️ untested no Guard exercised only by its unit tests; no live attempt to add a KotlinPoet import and run the product's generate path.
  • Outcome: ⚠️ 2 warnings across 1 run (7m3s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

♻️ Reviewed only the branch's changes since run 01M8DMDVNJTYKE4YK4KRNW4P4P approved; the rest of the branch carries that approval.

Findings carried from run 01M8DMDVNJTYKE4YK4KRNW4P4P, already decided there:

  • ⚠️ server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/writer/KotlinWriter.kt:233 - Simplification: the change adds a new public KotlinWriter.packageHeader(pkg) to the writer API. Its only caller is KotlinNaming.packageHeader, which no reference generator calls (its own allowlist note says so). The only effect is to move the typed \n\n line breaks into the writer package, so the KotlinNaming entry can leave the layout-ratchet allowlist. The intent does not list KotlinNaming as a file to convert. Recommended remedy: keep the old one-line body in KotlinNaming with its allowlist entry, and drop the new writer API. If the human wants an empty allowlist, keep it as is.

✅ No issues found.

⚠️ **Test** - 2 warnings
  • ⚠️ No live scenario driven: the Maven plugin metaobjects:generate run and before/after diff of Kotlin output were not attempted, so the moved generators have only in-process test evidence.
  • ⚠️ live validation verdict: inconclusive (0 of 4 scenarios were driven live against the product); untested: Kotlin entity generator emits through KotlinWriter with output unchanged in behavior, Kotlin enum and Spring config generators emit through KotlinWriter, Generated Kotlin output compiles without kotlinpoet on the path, Adversarial: reintroducing KotlinPoet is blocked at build time
  • Live validation: ⚠️ inconclusive - 0 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Kotlin entity generator emits through KotlinWriter with output unchanged in behavior ⏸️ untested no Only in-process unit tests ran. Live check needs metaobjects:generate through the Maven plugin on a fixture, diffed before and after the change; not attempted within budget.
Kotlin enum and Spring config generators emit through KotlinWriter ⏸️ untested no Same as above: in-process tests only, no live plugin or CLI run.
Generated Kotlin output compiles without kotlinpoet on the path ⏸️ untested no Compile gate ran in-process via the test suite, not against a live generate-then-kotlinc run of the product.
Adversarial: reintroducing KotlinPoet is blocked at build time ⏸️ untested no Guard exercised only by its unit tests; no live attempt to add a KotlinPoet import and run the product's generate path.
  • scripts/ci-local.sh --affected --strict-toolchains
  • Maven offline focused run: mvn -o -q -pl codegen-kotlin test -Dtest='KotlinEntityGeneratorTest,KotlinWriteGuardTest,KotlinLayoutRatchetTest,KotlinTypeMapperTest,EjectedAtBaseGeneratorsCompatTest' in server/java; surefire reports fresh, all pass (KotlinEntityGeneratorTest 12, KotlinWriteGuardTest 3, KotlinLayoutRatchetTest 20, KotlinTypeMapperTest 47, EjectedAtBaseGeneratorsCompatTest 3)
  • Same run's surefire output: CodegenCompileConformanceTest, EjectContractTest, KotlinSpringConfigGeneratorTest, KotlinEnumConformanceTest, KotlinOutputCompilesTest, KotlinWriterConformanceTest all 0 failures
  • grep of codegen-kotlin src/main for kotlinpoet: only comments and KotlinTypeName doc mention remain, no imports; pom.xml has no kotlinpoet dependency
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…erators onto KotlinWriter and drop KotlinPoet

The last Kotlin generators that built KotlinPoet specs now write through
KotlinWriter (ADR-0063): KotlinEntityGenerator (data class, Java builder,
cross-field properties, TPH <Sub>Validation, abstract interface shape and
MetaNetJson.kt), KotlinEnumEmitter and KotlinSpringConfigGenerator.
KotlinTypeMapper answers with the writer's own KotlinTypeName /
KotlinClassName, KotlinCrossFieldRules answers expression strings, and
KotlinPoetFileWriter is removed. The kotlinpoet dependency leaves
codegen-kotlin; kotlin-reflect, which it supplied at runtime, is declared
directly so consumers' runtime classpath is unchanged.

The layout ratchet's unconverted allowlist is now empty (KotlinNaming's
packageHeader delegates to the writer); the ratchet itself stays.

Generated output changes in layout only: the 32 regenerated goldens are
identical to the old ones once imports, `public`, package qualifiers,
whitespace and trailing commas are normalised, and their comment text is
unchanged. MetaNetJson.kt is byte-identical.

Owned entity / exposed-table / routes / relations / repository /
spring-config / api-docs copies ejected before 1.3.0 named KotlinPoet
types and must be re-ejected; the CHANGELOG upgrade note says so, and the
four KotlinPoet frozen copies in ejected-at-base (with their ejectWith
classes) are refreshed to the 1.3.0 eject output.

Docs and agent-context skill references that said Kotlin codegen runs on
KotlinPoet are corrected, and the shipped agent-context tree, its Python
copy, the agent-context conformance fixtures and the llms mirrors are
rebuilt.
@dmealing
dmealing merged commit b350754 into main Nov 27, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-130-kt-writer-4 branch November 27, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant